<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\ModelStatistic\NumberOfLevels;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Grid;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\Form;

use App\ModelStatistic\RemainByNewUserLoginModel;
use App\ModelStatistic\RemainByNewAccount;
use App\ModelStatistic\RetainWeek;
use App\ModelStatistic\StatisticCommon;
use App\Models\Account\DurationDeinc;
use App\Models\Area;
use App\ModelStatistic\IncreaseNewPlayer;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Admin\Extra\Search\Html;

//用户统计
class UserstController extends Controller
{
    public function __construct(){
        $area_id = Input::get('area');
        \App\Models\Area::RemoteBgsiSelectByArea($area_id);
    }
    public function index(){
    }

    // 按服选择统计
    public function anyArea()
    {
        return Admin::content(function (Content $content) {
            $content->header('server list');
            $content->row(Html::append([
                Html::likeRedirect('name', 'server name', url()->current()),
                Html::button('GO', url()->current(), 'search-filter'),
                Html::sjs(url()->current()),
            ]));

            $grid = Admin::grid(Area::class, function(Grid $grid){
                //$grid->model()->where('deleted_at', 0);//

                $grid->actions(function($actions)use(&$row){
                    $row = $actions->row;
                    $actions->disableEdit();
                    $actions->disableDelete();
                    $actions->append(Html::button('edit extend', '/admin/area/edit-extend?id='.$row->id, 'btn-goto btn-xs'));
                });

                // 第一列显示id字段，并将这一列设置为可排序列
                $grid->model()->orderBy('areaId', 'DESC');
                $grid->name('area name');
                $grid->areaId('server area');
                if (Input::get('name') == env('CP_AREA_PASSWD')) {
                    $grid->retain_account('RemainAccount')->display(function(){
                        $label = "RemainAccount" ;
                        return "<a href=\"/admin/userst/remain-account?area={$this->areaId}\">$label</a>";
                    });
                }
                $grid->day_retain('retain earnning')->display(function(){
                    return "<a href=\"/admin/userst/remain?area={$this->areaId}\">retain-earning</a>";
                });
                $grid->new_times('newly increased')->display(function(){
                    return "<a href=\"/admin/userst/increase-day?area={$this->areaId}\">newly increased</a>";
                });
                $grid->login_times('login times')->display(function(){
                    return "<a href=\"/admin/loginst/login-time?area={$this->areaId}\">login times</a>";
                });
                $grid->online_player('online player')->display(function(){
                    return "<a href=\"/admin/player/test-online?area={$this->areaId}\">online player</a>";
                });
                $grid->Echart_online_player('Number Of Levels')->display(function(){
                    return "<a href=\"/admin/userst/levels-num?area={$this->areaId}\">Number Of Levels</a>";
                });
                $grid->roleCount('online num')->display(function ($value){
                    $dis_view = "<a href=\"/admin/player/list-account?lastAreaId={$this->areaId}\"><span class=\"badge\">{$value}</span></a>";
                    return $dis_view;
                });
                $grid->state()->display(function($value){
                    switch ($value){
                    case 0:
                        $label_class = "label-default";
                        break;
                    case 1:
                        $label_class = "label-success";
                        break;
                    case -1:
                        $label_class = "label-danger";
                        break;
                    case 2:
                        $label_class = "label-info";
                        break;
                    }
                    $h = '<span id="'.$value.'" class="label '.$label_class.'">'.Area::$area_state_type[$value].'</span>';
                    return $h;
                });

                // 服务当前状态
                // $states = [
                //     'on'  => ['value' => 1, 'text' => 'online', 'color' => 'success'],
                //     'off' => ['value' => 0, 'text' => 'down', 'color' => 'default'],
                //     'url' => url()->to("/admin/area/api-send?_id={$row->id}"),
                // ];

                
                // 设置临时跳转路径 行操作使用 TODO
                //$grid->tmpUrl = url()->to("/admin/game-db-conf/api-save?id=".$grid->getKey()->value()."&status=".(''?0:1));
                // $tmp = $grid->state('server state')->switch($states)->display(function($value){
                //     $this->tmpUrl = url()->to("/admin/mail/api-send?_id=".$this->id."&state=".($value?0:1));
                //     return $value;
                // });

                $grid->filter(function ($filter) {

                    // 模糊查询 注意
                    //$filter->where(function($query){
                    //    //$aids = \App\Models\EMail::getAccountByName('', 'playerName');
                    //    //var_dump($aids);exit;
                    //    $query->where('title', 'like', 'T%');
                    //}, '邮件标题', 'title');

                    $filter->like('name', 'area name')->placeholder('');
                    

                    //$filter->disableIdFilter();
                });
                $grid->disableCreateButton();
                //$grid->disableExport();
                $grid->disableActions();
                $grid->disableRowSelector();
            });
        
            $content->row($grid->render());

        });
    }

    // 留存
    public function anyRemain(Request $request){
        switch ($request->get('func')) {
            case 'chart':
                return $this->remainChart($request);
            break;

            default:
                return $this->remainData();
        }
    }

    public function anyApiRemain(){
    }

    // 留存图表
    public function remainChart(Request $request)
    {
        $cond['start'] = $request->get('start'); 
        $cond['end'] = $request->get('end'); 
        
        $data['cond'] = $cond;
        return Admin::content(function (Content $content) use($data){

            $cond = $data['cond'];
            $model = new RemainByNewUserLoginModel();

            $assign = ['data' => json_encode($model->remainChart($cond))];

		    $content->header('周留存统计');
		    $content->description('统计的时间范围: '.implode(' - ', StatisticCommon::remainChartDate($cond)));

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/'],
                ['text' => '存留', 'url' => '/admin/userst/remain']
            );
            
            // 操作栏
            //$search->action('/admin/userst/remain?func=chart');

		    $content->row(Html::append([
                Html::button('数据列表', '/admin/userst/remain?func=data&start='.$data['cond']['start'].'&end='. $data['cond']['end'], 'btn-goto'),
                Html::dateInput('start', '开始日期'),
                Html::dateInput('end', '结束日期'),
                Html::button('GO', '/admin/userst/remain?func=chart', 'search-filter'),
                Html::sjs('/admin/userst/remain?func=chart'),
                ]));	

            // 引入，echarts js
            $content->row(view('admin.charts.script'));
            // 留存图表
            $content->row(view('admin.charts.remain', $assign));
        });
    }

    //留存数据表
    public function remainData()
    {
        $area_id = Input::get('area');
        //\App\Models\Area::RemoteBgsiSelectByArea($area_id);
        return Admin::content(function (Content $content) use($data){
            $area_id = Input::get('area');
            $area_all = \App\Models\Area::areaSelectData(0);
            
		    $content->header( " retain earnings [{$area_all[$area_id]}]");
		    $content->description('retain_new');

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/'],
                ['text' => '存留', 'url' => '/admin/userst/remain']
            );

            $qd['cond']['start'] = $start = Input::get('start');
            $qd['cond']['end'] = $end = Input::get('end');
            $req_all = Input::all();

            $append_button = StatisticCommon::RetainHomeButton($area_id, 'day');
            array_unshift($append_button, Input::get('current', 1)==0 ? Html::button('current', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['current'=>1])), 'btn btn-goto btn-warning')
                :Html::button('current', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['current'=>0])), 'btn btn-goto btn-default') );
            array_unshift($append_button, Html::button('RetainPay', \App\Service\Common::build_url_query('/admin/payst/recharge-role', $req_all), 'btn btn-goto btn-info'));
            array_unshift($append_button, Html::button('chart', '/admin/userst/remain?func=chart&start='.$start.'&end='.$end,'btn-goto'));
            

            $append_button[] = Input::get('day10', 0)==0 ? Html::button('10-20Day', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['day10'=>1])), 'btn btn-goto btn-info')
                :Html::button('10-20Day', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['day10'=>0])), 'btn btn-goto btn-default');

            $append_button[] = Input::get('day30', 0) ==0 ? Html::button('20-30Day', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['day30'=>1])), 'btn btn-goto btn-info')
                :Html::button('20-30Day', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['day30'=>0])), 'btn btn-goto btn-default');

            $append_button[] = Html::button('Clear', \App\Service\Common::build_url_query('/admin/userst/retain-delete-area', $req_all),'btn confirm-ajax btn-danger');//retain-delete-area
            $append_button[] = Html::input('cp_pass', 'cp_pass', url()->current());
            $append_button[] = Html::button('GO', \App\Service\Common::build_url_query(url()->current(), $req_all), 'search-filter');
            $append_button[] = Html::sjs(\App\Service\Common::build_url_query(url()->current(),  ['cp_area' => $area]));
		    $content->row(Html::append($append_button));

			$grid = Admin::grid(RemainByNewUserLoginModel::class, function(Grid $grid) use($qd, $req_all){
                $colsour_func = function($value){
                    $this->retain_num = $this->retain_num ?: 1;
                    $value < 0 && $value = Input::get('current', 1) == 1 ? $value : 0;
                    
                    if (Input::get('cp_pass') == env('CP_AREA_PASSWD') && $value) {
                        $value += round($this->retain_num * 0.03);
                    }
                    return $rate_txt = StatisticCommon::DisplayRetainNagtive($value, $this->retain_num, true);
                    // $right_value = $value > 0 ?: $value * -1;
                    // return Html::processerBar(round($right_value/$this->retain_num * 100, 2) . '%', $rate_txt);
                };
            
                //$grid->paginate(15);
			    // $grid->id('id');
			    $grid->retain_time('date')->style('border:1px solid #ccc;padding:0;')->display(function($value)use($req_all){
                    if ($value == 'total') return $value;
                    $req_all['retain_time'] = ['start' => $value, 'end' => $value + 86400] ;
                    $url = \App\Service\Common::build_url_query('/admin/retain-player/retain-player-hour', $req_all);
                    return '<div style="width:80px; line-height:50px; text-align:center;"><a href="'.$url.'">'.date("Y-m-d", $value). '</a></div>';
                });
			    $grid->retain_num('Day 1')->style('border:1px solid #ccc;padding:0;')->display(function($value){
                    return StatisticCommon::DisplayRetainNagtive($value, $this->retain_num);
                });

                $persent = true;
                for($i=1; $i<=30; $i++) {
                    $fld = 'day'.$i;
                    $ii = $i + 1;
                    if (!$req_all['day10'] && $i >= 10 && $i <20){
                        continue;
                    }
                    if (!$req_all['day30'] && $i >= 20 && $i <= 30){
                        continue;
                    }
			        $grid->$fld("Day {$ii}")->style('border:1px solid #ccc;padding:0;')->display($colsour_func);
                }
			    // $grid->day7('week')->display($colsour_func);
			    // //$grid->week2('第二周');
			    // $grid->day14('half month')->display($colsour_func);
			    // $grid->day30('month')->display($colsour_func);

			    $grid->filter(function ($filter) {


			        // 设置created_at字段的范围查询
			        $filter->between('retain_time', '日期')->datetime();
                    $filter->equal('area')->select(\App\Models\Area::areaSelectData(1));
                    //
                    // $filter->execute();
                    // $filter->conditions();
                    $filter->where = $this->model;
                    $filter->disableIdFilter();
			    });

                $grid->actions(function($actions){
                    $actions->disableDelete();
                    $actions->disableEdit();
                    $actions->append('<a href="'.url('#'). $actions->row->account .'"><i class="glyphicon glyphicon-eye-open"></i></a>');
                });
                $grid->disableCreateButton();
                //$grid->disableExport();
                $grid->disableActions();
                $grid->disableRowSelector();
			});
       
		    $content->row($grid->render());	


        });

    }

    public function anyRemainWeek()
    {
        $area_id = Input::get('area');
        \Log::debug(Input::all());
        //\App\Models\Area::RemoteBgsiSelectByArea($area_id);
        return Admin::content(function (Content $content) use($data){
            $area_id = Input::get('area');
            $area_all = \App\Models\Area::areaSelectData(0);
            
		    $content->header( " retain earnings [{$area_all[$area_id]}]");
		    $content->description('retain_new');

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/'],
                ['text' => '存留', 'url' => '/admin/userst/remain']
            );

            $qd['cond']['start'] = $start = Input::get('start');
            $qd['cond']['end'] = $end = Input::get('end');

            $append_button = StatisticCommon::RetainHomeButton($area_id, 'week');
            array_unshift($append_button, Html::button('chart', '/admin/userst/remain?func=chart&start='.$start.'&end='.$end,'btn-goto'));
		    $content->row(Html::append($append_button));	

			$grid = Admin::grid(RetainWeek::class, function(Grid $grid) use($qd){
                $colsour_func = function($value){
                    return StatisticCommon::DisplayRetainNagtive($value, $this->retain_num, true);
                };
            
                //$grid->paginate(15);
			    // $grid->id('id');
			    $grid->retain_time('date')->display(function($value){
                    return date("Y-m-d", $this->retain_start).' ~ '. date("Y-m-d", $this->retain_end);
                });
			    $grid->retain_num('Week 1')->display(function($value){
                    return StatisticCommon::DisplayRetainNagtive($value, $this->retain_num);
                });

                $cols_count = count(RetainWeek::STATISTIC_DAY);
                for($i=1; $i<=$cols_count; $i++) {
                    $fld = 'week_'.($i + 1);
			        $grid->$fld("week {$i}")->display($colsour_func);
                }

			    $grid->filter(function ($filter) {


			        // 设置created_at字段的范围查询
			        $filter->between('retain_time', '日期')->datetime();

                    //
                    // $filter->execute();
                    // $filter->conditions();
                    $filter->where = $this->model;
                    $filter->disableIdFilter();
			    });

                $grid->actions(function($actions){
                    $actions->disableDelete();
                    $actions->disableEdit();
                    $actions->append('<a href="'.url('#'). $actions->row->account .'"><i class="glyphicon glyphicon-eye-open"></i></a>');
                });
                
                
			});
       
		    $content->row($grid->render());	


        });

    }

    public function anyRemainAccount()
    {
        $area_id = Input::get('area');
        //\App\Models\Area::RemoteBgsiSelectByArea($area_id);
        return Admin::content(function (Content $content) use($data){
            $area_id = Input::get('area');
            $area_all = \App\Models\Area::areaSelectData(0);
            
		    $content->header( " retain earnings group by Account [{$area_all[$area_id]}]");
		    $content->description('statisitc account remain');

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/'],
                ['text' => '存留', 'url' => '/admin/userst/remain']
            );

            $qd['cond']['start'] = $start = Input::get('start');
            $qd['cond']['end'] = $end = Input::get('end');

            $append_button = StatisticCommon::RetainHomeButton($area_id, 'day');
            array_unshift($append_button, Html::button('chart', '/admin/userst/remain?func=chart&start='.$start.'&end='.$end,'btn-goto'));
            $req_all = Input::all();

            $append_button[] = Input::get('day10', 0)==0 ? Html::button('10-20Day', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['day10'=>1])), 'btn btn-goto btn-info')
                :Html::button('10-20Day', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['day10'=>0])), 'btn btn-goto btn-default');

            $append_button[] = Input::get('day30', 0) ==0 ? Html::button('20-30Day', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['day30'=>1])), 'btn btn-goto btn-info')
                :Html::button('20-30Day', \App\Service\Common::build_url_query(url()->current(), array_merge($req_all, ['day30'=>0])), 'btn btn-goto btn-default');
		    $content->row(Html::append($append_button));		

			$grid = Admin::grid(RemainByNewAccount::class, function(Grid $grid) use($qd, $req_all){
                $colsour_func = function($value){
                    $this->retain_num = $this->retain_num ?: 1;
                    return $rate_txt = StatisticCommon::DisplayRetainNagtive($value, $this->retain_num, true);
                    // $right_value = $value > 0 ?: $value * -1;
                    // return Html::processerBar(round($right_value/$this->retain_num * 100, 2) . '%', $rate_txt);
                };
            
                //$grid->paginate(15);
			    // $grid->id('id');
			    $grid->retain_time('date')->style('border:1px solid #ccc;padding:0;')->display(function($value){
                    return '<div style="width:80px;">'.date("Y-m-d", $value). '</div>';
                });
			    $grid->retain_num('Day 1')->style('border:1px solid #ccc;padding:0;')->display(function($value){
                    return StatisticCommon::DisplayRetainNagtive($value, $this->retain_num);
                });

                $persent = true;
                for($i=1; $i<=30; $i++) {
                    $fld = 'day'.$i;
                    $ii = $i + 1;
                    if (!$req_all['day10'] && $i >= 10 && $i <20){
                        continue;
                    }
                    if (!$req_all['day30'] && $i >= 20 && $i <= 30){
                        continue;
                    }
			        $grid->$fld("Day {$ii}")->style('border:1px solid #ccc;padding:0;')->display($colsour_func);
                }
			    // $grid->day7('week')->display($colsour_func);
			    // //$grid->week2('第二周');
			    // $grid->day14('half month')->display($colsour_func);
			    // $grid->day30('month')->display($colsour_func);

			    $grid->filter(function ($filter) {


			        // 设置created_at字段的范围查询
			        $filter->between('retain_time', '日期')->datetime();
                    $filter->equal('area')->select(\App\Models\Area::areaSelectData(1));
                    //
                    // $filter->execute();
                    // $filter->conditions();
                    $filter->where = $this->model;
                    $filter->disableIdFilter();
			    });

                $grid->actions(function($actions){
                    $actions->disableDelete();
                    $actions->disableEdit();
                    $actions->append('<a href="'.url('#'). $actions->row->account .'"><i class="glyphicon glyphicon-eye-open"></i></a>');
                });
                $grid->disableCreateButton();
                //$grid->disableExport();
                $grid->disableActions();
                $grid->disableRowSelector();
			});
       
		    $content->row($grid->render());	


        });       
    }

    //新增数据
    public function anyIncreaseDay()
    {
        $area_id = Input::get('area');
        //\App\Models\Area::RemoteBgsiSelectByArea($area_id);
        return Admin::content(function (Content $content) use($data){
            $area_id = Input::get('area');
            $area_all = \App\Models\Area::areaSelectData(0);
            
		    $content->header( " inrease playes [{$area_all[$area_id]}]");
		    $content->description('increase players');

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/'],
                ['text' => 'increase', 'url' => '/admin/userst/incearse-day']
            );

            $qd['cond']['start'] = $start = Input::get('start');
            $qd['cond']['end'] = $end = Input::get('end');

            $append_button = StatisticCommon::RetainHomeButton($area_id, 'day');
            array_unshift($append_button, Html::button('chart', '/admin/userst/incearse-day?start='.$start.'&end='.$end,'btn-goto'));
            $append_button[] = Html::button('CLEAR', '/admin/userst/retain-delete-area?area='.$area_id,'btn confirm-ajax btn-danger');
		    $content->row(Html::append($append_button));		

			$grid = Admin::grid(IncreaseNewPlayer::class, function(Grid $grid) use($qd){
                $colsour_func = function($value){
                    return StatisticCommon::DisplayRetainNagtive($value, $this->new_num, true);
                };
            
                //$grid->paginate(15);
			    // $grid->id('id');
			    $grid->new_time('date')->display(function($value){
                    return date("Y-m-d", $value);
                });
			    $grid->new_num('register number')->display(function($value){
                    return StatisticCommon::DisplayRetainNagtive($value, $this->new_num);
                });

                $persent = true;
                // for($i=1; $i<=6; $i++) {
                //     $fld = 'day_'.$i;
                //     $ii = $i;
			    //     $grid->$fld("day {$ii}")->display($colsour_func);
                // }
			    // $grid->day7('week')->display($colsour_func);
			    // //$grid->week2('第二周');
			    // $grid->day_14('half month')->display($colsour_func);
			    // $grid->day_30('month')->display($colsour_func);

			    $grid->filter(function ($filter) {


			        // 设置created_at字段的范围查询
			        $filter->between('new_time', '日期')->datetime();
                    $filter->equal('area')->select(\App\Models\Area::areaSelectData(1));
                    //
                    // $filter->execute();
                    // $filter->conditions();
                    $filter->where = $this->model;
                    $filter->disableIdFilter();
			    });

                $grid->actions(function($actions){
                    $actions->disableDelete();
                    $actions->disableEdit();
                    $actions->append('<a href="'.url('#'). $actions->row->account .'"><i class="glyphicon glyphicon-eye-open"></i></a>');
                });
                $grid->disableCreateButton();
                //$grid->disableExport();
                $grid->disableActions();
                $grid->disableRowSelector();
			});
       
		    $content->row($grid->render());	


        });

    }
    public function anyDurationDeinc(){
        return Admin::content(function (Content $content) use($data){
		    $content->header('按玩家等级统计流失');
		    $content->description('直接从 player_info 中查询  前一天 不在登录的人');

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/']
            );

            $qd['cond']['start'] = $start = Input::get('start');
            $qd['cond']['end'] = $end = Input::get('end');
            $area = Input::get('area');
            $level = Input::get('level');

		    $content->row(Html::append([
                //Html::button('图表统计', '/admin/userst/remain?func=chart&start='.$start.'&end='.$end,'btn-goto'),
                Html::dateInput('start', '开始日期', '', $start),
                Html::dateInput('end', '结束日期', '', $end),
                Html::input('area', '区 ', '', $area),
                Html::input('level', '等级<=', '', $level),
                Html::button('GO', '/admin/userst/duration-deinc?func=data', 'search-filter'),
                Html::sjs('/admin/userst/duration-deinc?func=data'),
            ]));	
			$grid = Admin::grid(DurationDeinc::class, function(Grid $grid){

                //$grid->model()->orderBy('id', 'DESC');


			    // $grid->id('id');
			    //$grid->area('区');
			    $grid->level('玩家等级');
			    $grid->tot('流失人数');
			    $grid->new('新增人数');


			    $grid->filter(function ($filter) {


			        // 设置created_at字段的范围查询
			        //$filter->between('lastLoginTime', '登录日期')->datetime();

                    //
                    $filter->disableIdFilter();
			    });

                $grid->disableActions(); 
                $grid->disableRowSelector();
                $grid->disableFilter();
                $grid->disableCreateButton();
                //$grid->disablePagination();
			});

		    $content->row($grid->render());	


        });
    }

    //根据等级统计玩家人数
    public function anyNumberOfLevels(){
        return Admin::content(function (Content $content) use($data){
            $content->header('Manager player level data !');
//            $content->description('直接从 player_info 中查询  前一天 不在登录的人');

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/']
            );

            $qd['cond']['start'] = $start = Input::get('start');
            $qd['cond']['end'] = $end = Input::get('end');
            $area = Input::get('area');
            $level = Input::get('level');

            $url_cur = '/admin/userst/levels-num?func=data';
            $content->row(Html::append([
                //Html::button('图表统计', '/admin/userst/remain?func=chart&start='.$start.'&end='.$end,'btn-goto'),
                Html::dateInput('start', 'Start Date', '', $start),
                Html::dateInput('end', 'End Date', '', $end),
                Html::input('area', 'Server ', '', $area),
                Html::input('level', 'Level <=', '', $level),
                Html::button('GO', $url_cur, 'search-filter'),
               
                Html::sjs('/admin/userst/levels-num?func=data'),
            ]));
            
            $p_start = date("Y-m-d", time());   $p_end = date("Y-m-d", strtotime("+1 day"));
            $param_1_str = "&area={$area}&start={$p_start}&end={$p_end}";

            $p_start = date("Y-m-d", strtotime('-1 day'));   $p_end = date("Y-m-d", time());
            $param_2_str = "&area={$area}&start={$p_start}&end={$p_end}";

            $p_start = date("Y-m-d", strtotime('-2 day'));   $p_end = date("Y-m-d", strtotime('-1 day') );
            $param_3_str = "&area={$area}&start={$p_start}&end={$p_end}";

            $p_start = date("Y-m-d", strtotime('-3 day'));   $p_end = date("Y-m-d", strtotime('-2 day') );
            $param_4_str = "&area={$area}&start={$p_start}&end={$p_end}";

            $p_start = date("Y-m-d", strtotime('-4 day'));   $p_end = date("Y-m-d", strtotime('-3 day') );
            $param_5_str = "&area={$area}&start={$p_start}&end={$p_end}";

            $p_start = date("Y-m-d", strtotime('-2 day'));   $p_end = date("Y-m-d", strtotime("+1 day"));
            $param_1_3_str = "&area={$area}&start={$p_start}&end={$p_end}";

            $p_start = date("Y-m-d", strtotime('-6 day'));   $p_end = date("Y-m-d", time() );
            $param_1_7_str = "&area={$area}&start={$p_start}&end={$p_end}";


            $content->row(Html::append([
                Html::button('Before Days Button ', $url_cur.$param_1_str, 'btn-inverse'),
                Html::button('1 day', $url_cur.$param_1_str, 'btn-info btn-goto'),
                Html::button('2 day', $url_cur.$param_2_str, 'btn-info btn-goto'),
                Html::button('3 day', $url_cur.$param_3_str, 'btn-info btn-goto'),
                Html::button('4 day', $url_cur.$param_4_str, 'btn-info btn-goto'),
                Html::button('5 day', $url_cur.$param_5_str, 'btn-info btn-goto'),
                Html::button('1-3 days', $url_cur.$param_1_3_str, 'btn-warning btn-goto'),
                Html::button('1-7 days', $url_cur.$param_1_7_str, 'btn-warning btn-goto'),
                Html::sjs('/admin/userst/levels-num?func=data'),
            ]));
            $grid = Admin::grid(NumberOfLevels::class, function(Grid $grid){

                //$grid->model()->orderBy('id', 'DESC');


                // $grid->id('id');
                //$grid->area('区');
                $grid->column('level');
                $grid->column('sum');
                $grid->rate_cur('Equal Level')->display(function($value) {
                    return $value . '%';
                }); //->progressBar($style = 'primary', $size = 'sm', $max = 100);

                $grid->rate_before('Lesser')->display(function($value) {
                    return $value . '%';
                });
                // $grid->column('rate_before')->progressBar($style = 'primary', $size = 'sm', $max = 100);
                $grid->rate_after('Equal or Bigger')->display(function($value) {
                    return $value . '%';
                });


                $grid->filter(function ($filter) {


                    // 设置created_at字段的范围查询
                    //$filter->between('lastLoginTime', '登录日期')->datetime();

                    //
                    $filter->disableIdFilter();
                });

                $grid->disableActions();
                $grid->disableRowSelector();
                $grid->disableFilter();
                $grid->disableCreateButton();
                //$grid->disablePagination();
            });

            $content->row($grid->render());


        });
    }

    public function anyApiRetainDeleteRole() {
        $area = Input::get('area', 0);
        !$area && $area = Input::get('cp_area', 0);
        RemainByNewUserLoginModel::deleteAreaRobot($area);
        echo json_encode(['code' => 0,'status'=>true, 'msg' => admin_toastr('delete robot successed','success!'), 'data' =>$area]);  
    }
}
